#!/bin/csh
#  Copyright (C) 2002 Regents of the University of Michigan, portions used with permission 
#  For more information, see http://csem.engin.umich.edu/tools/swmf
# tec2bin:   *.dat files into *.plt files using preplot
#

if($1 == 'help' || $1 == '-h' || $1 == '-help')then
   echo "Usage:"
   echo ""
   echo "ppgz [KEEP]"
   echo ""
   echo "This routine is intended for use only with tecplot files, Which"
   echo "it converts from ascii(.dat) to binary(.plt). The script only 
   echo "runs on platforms which have the preplot program installted in
   echo "/usr/contrib/bin/preplot."
   echo ""
   echo "The script looks for .dat.gz files to process.  It unzips them,"
   echo "runs preplot on them.  By default it then deletes them."
   echo ""
   echo "If the 2nd argument, KEEP, exists the files are not deleted but"
   echo "are gzipped again for storage."
   echo ""
   echo "Examples:"
   echo ""
   echo "ppgz      =>process all .dat.gz files in current dir."
   echo "ppgz KEEP =>process all .dat.gz files in IO2/ dir. Do not delete."
   echo ""
   exit
endif

set dir='./'

echo 'Seaching for files in '${dir}' --- preplot logfile: '${dir}'preplot.log' 
echo ''

foreach i (${dir}*.dat.gz)
    set f = `dirname $i`/`basename $i .dat.gz`
    echo '-----------------------------------------------------------------'
    echo 'processing file: '${i}
    echo '  gunzip ... ('${i}')'
    gunzip $i
    echo '  preplot ... ('${f}'.dat => '${f}'.plt)'
    if (`hostname` == rhodot.engin.umich.edu) \
       /usr/local/bin/preplot ${f}.dat >> ${dir}preplot.log
    if (`hostname` != rhodot.engin.umich.edu) \
       /usr/contrib/bin/preplot ${f}.dat >> ${dir}preplot.log
    if($1 == '')then
       echo '  deleting ... ('${f}'.dat)'
       rm -f ${f}.dat
    else
       echo '  gzip ... ('${f}'.dat => '${f}'.dat.gz)'
       gzip ${f}.dat
    endif
end
